#include "Luzes.h"

#include <GL\glui.h>
#include <iostream>

using namespace std;
/*
 * Construtor
 */
Luzes::Luzes(int GL_LIGHT) {
	this->GL_LIGHT = GL_LIGHT;
}

void Luzes::setAmbiente(float r, float g, float b, float a) {
	ambiente[0] = r;
	ambiente[1] = g;
	ambiente[2] = b;
	ambiente[3] = a;
	glLightfv(GL_LIGHT, GL_AMBIENT, ambiente);
}
void Luzes::setDifusa(float r, float g, float b, float a) {
	difusa[0] = r;
	difusa[1] = g;
	difusa[2] = b;
	difusa[3] = a;
	glLightfv(GL_LIGHT, GL_DIFFUSE, difusa);
}
void Luzes::setEspecular(float r, float g, float b, float a) {
	especular[0] = r;
	especular[1] = g;
	especular[2] = b;
	especular[3] = a;
	glLightfv(GL_LIGHT, GL_SPECULAR, especular);
}
void Luzes::setGL_LIGHT(int l) {
	this->GL_LIGHT = l;
}

void Luzes::setEnabled(int enabled) {
	this->enabled = enabled;
	if(enabled) {
		glEnable(this->GL_LIGHT);
	} else {
		glDisable(GL_LIGHT);
	}
}

float * Luzes::getAmbiente() {
	return this->ambiente;
}
float * Luzes::getDifusa() {
	return this->difusa;
}
float * Luzes::getEspecular() {
	return this->especular;
}
int Luzes::getEnabled() const {
	return this->enabled;
}
float Luzes::getGL_LIGHT() const {
	return this->GL_LIGHT;
}

/*
 * OMNI
 */

Omni::Omni() {
}

Omni::Omni(int GL_LIGHT) : Luzes(GL_LIGHT){
}

void Omni::setLocalizacao(float x, float y, float z, float w) {
	localizacao[0] = x;
	localizacao[1] = y;
	localizacao[2] = z;
	localizacao[3] = w;
}

float * Omni::getLocalizacao() {
	return this->localizacao;
}

void Omni::aplica() {
	glLightfv(this->getGL_LIGHT(), GL_AMBIENT, this->getAmbiente());
	glLightfv(this->getGL_LIGHT(), GL_DIFFUSE, this->getDifusa());
	glLightfv(this->getGL_LIGHT(), GL_SPECULAR, this->getEspecular());
	glLightfv(this->getGL_LIGHT(), GL_POSITION, localizacao);
}

/*
 * SPOT
 */

Spot::Spot() {
}

Spot::Spot(int GL_LIGHT) : Luzes(GL_LIGHT){
}

void Spot::setLocalizacao(float x, float y, float z) {
	localizacao[0] = x;
	localizacao[1] = y;
	localizacao[2] = z;
	glLightfv(this->getGL_LIGHT(), GL_POSITION, localizacao);
}
void Spot::setTarget(float x, float y, float z) {
	target[0] = x;
	target[1] = y;
	target[2] = z;
	// NAO SEI O QUE E PARA POR AQUI
}

void Spot::setAngulo(float angulo) {
	this->angulo = angulo;
	glLightf(this->getGL_LIGHT(), GL_SPOT_CUTOFF, angulo);
}
void Spot::setExponent(float exponent) {
	this->exponent = exponent;
	glLightf(this->getGL_LIGHT(), GL_SPOT_EXPONENT, exponent);
}

float * Spot::getLocalizacao() {
	return this->localizacao;
}
float * Spot::getTarget() {
	return this->target;
}
float Spot::getAngulo() const {
	return this->angulo;
}
float Spot::getExponent() const {
	return this->exponent;
}

void Spot::aplica() {
	glLightfv(this->getGL_LIGHT(), GL_AMBIENT, this->getAmbiente());
	glLightfv(this->getGL_LIGHT(), GL_DIFFUSE, this->getDifusa());
	glLightfv(this->getGL_LIGHT(), GL_SPECULAR, this->getEspecular());
	glLightfv(this->getGL_LIGHT(), GL_POSITION, localizacao);
	glLightf(this->getGL_LIGHT(), GL_SPOT_CUTOFF, angulo);
	glLightfv(this->getGL_LIGHT(), GL_SPOT_DIRECTION, this->getTarget());
	glLightf(this->getGL_LIGHT(), GL_SPOT_EXPONENT, this->getExponent());
}
